<template>
	<view>
		<production-detail detailType="production" :detailObj="detailInfo"></production-detail>
	</view>
</template>

<script>
	import productionDetail from "../../qualitySafetyManagement/components/production_detail.vue"
	import { getPicture } from '@/api/doc.js' //获取图片
	import { projectBaseGet } from "@/api/qualitySafetyManagement/qualitySafetyManagement.js"
	export default {
		name:'detail',
		components:{
			productionDetail
		},
		data() {
			return {
				detailInfo:{}
			}
		},
		onLoad(param) {
			if(param && param.id) {
				this.getDetail(param.id)
			}
			
		},
		methods: {
			getDetail(id){
				projectBaseGet({id}).then(async res => {
					if(!res.success) return
					this.detailInfo = res.result
					if(this.$store.getters.dictMap['project_base_type']){
						this.detailInfo.projectBaseType = this.$store.getters.dictMap['project_base_type'].find(it => it.code === this.detailInfo.projectBaseType).name
					}
					
					if(this.$store.getters.dictMap['lead_the_inspection_team']){
						this.detailInfo.checkPerson = this.$store.getters.dictMap['lead_the_inspection_team'].find(it => it.code === this.detailInfo.checkPerson).name
					}
					if(this.detailInfo.runCheckDocId) {
						let test1 = await this.getItemImage(this.detailInfo.runCheckDocId)
						this.$set(this.detailInfo, 'imgs1', test1)
					}else {
						this.detailInfo.imgs1 = []
					}
					if(this.detailInfo.rectificationDocId) {
						let test2 = await this.getItemImage(this.detailInfo.rectificationDocId)
						this.$set(this.detailInfo, 'imgs2', test2)
					}else {
						this.detailInfo.imgs2 = []
					}
					if(this.detailInfo.checkDocId) {
						let test3 = await this.getItemImage(this.detailInfo.checkDocId)
						this.$set(this.detailInfo, 'imgs3', test3)
					}else {
						this.detailInfo.imgs3 = []
					}
				})
			},
			async getItemImage(docId) {
				return await new Promise((resolve, reject) => {
					getPicture({docId}).then(res => {
						resolve(res.result.map(it => ({
							id:it.id,
							src:this.$config.IMG_FILE_URL + it.fileName
						})));
					}).catch(err => reject(err))
				})
			},
		}
	}
</script>

<style>

</style>
